<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<div class="project_contents">
	<h1>Create Work</h1>
	<div class="project_in">
		<form method="post">
			<table id="create_work_table">
				<tr>
				<td class="td_title"></td>
				<td colspan="3"><label id="has_errors"></label> 
					<label id="complete"></label>
				</td>
				</tr>
				<tr>
					<td class="td_title"><label>유형*</label></td>
					<td><select id="form_workType">
							<option value="새기능">새기능</option>
							<option value="결함">결함</option>
					</select></td>
					<td class="td_title"><label>상태*</label></td>
					<td><select id="form_workState">
							<option value="신규">신규</option>
							<option value="진행">진행</option>
							<option value="완료">완료</option>
							<option value="거절">거절</option>
					</select></td>
				</tr>
				<tr>
					<td class="td_title"><label>제목*</label></td>
					<td colspan=3><input type="text" placeholder="제목을 입력하세요"
						id="form_workTitle" style="width: 650px" /></td>
				</tr>
				<tr>
					<td class="td_title"><label>설명</label></td>
					<td colspan=3><textarea placeholder="설명을 입력하세요"
							id="workExplanation"></textarea></td>
				</tr>
				<tr>
					<td class="td_title"><label>우선순위*</label></td>
					<td><select id="form_workPriority">
							<option value="보통">보통</option>
							<option value="낮음">낮음</option>
							<option value="높음">높음</option>
							<option value="즉시">즉시</option>
					</select></td>
					<td class="td_title"><label>담당자*</label></td>
					<td><input type="text" placeholder="id를 입력하세요" id="form_id" />
					</td>
				</tr>
				<tr>
					<td class="td_title"><label>상위일감</label></td>
					<td><input type="text" placeholder="상위일감을 입력하세요"
						id="form_upperWork" /></td>
					<td class="td_title"><label>시작시간</label></td>
					<td><input type="text" placeholder="yyyy-mm-dd"
						id="form_startDate" /></td>
				</tr>
				<tr>
					<td class="td_title"><label>파일</label></td>
					<td><input type="text" placeholder="파일번호를 입력하시오" id="form_file" />
					</td>
					<td class="td_title"><label>마감시간</label></td>
					<td><input type="text" placeholder = "yyyy-mm-dd"
						id="form_deadDate" /></td>
				</tr>
				<tr>
					<td class="td_title">문서</td>
					<td>
						<input type="text" placeholder="문서번호를 입력하시오" id="form_document">
					</td>
					<td class="td_title"><label>진척도</label></td>
					<td><select id="form_workProgress">
							<option value="0">0%</option>
							<option value="10">10%</option>
							<option value="20">20%</option>
							<option value="30">30%</option>
							<option value="40">40%</option>
							<option value="50">50%</option>
							<option value="60">60%</option>
							<option value="70">70%</option>
							<option value="80">80%</option>
							<option value="90">90%</option>
							<option value="100">100%</option>
					</select></td>
				</tr>
			</table>
			<div class="btn_margin">
				<input type="button" id="modify_submit" class="btn" value="업무수정"
					>
			</div>
		</form>
		<script>
			$('input#modify_submit').click(function(){
				var relationNo = '${workTracer.relationNo}';
				var relationNo2 = '${workDocFileTracer.relationNo}';
				
				if(relationNo == ""){
					relationNo = 0;
				}
				if(relationNo2 == ""){
					relationNo2 = 0;
				}
				
				project_modifywork_action(relationNo, relationNo2);
			});
		
			$("input#form_startDate").datepick({
				dateFormat : 'yyyy-mm-dd'
			});
			$("input#form_deadDate").datepick({
				dateFormat : 'yyyy-mm-dd'
			});
			
			
			 $.ajax({
				url : "project/createWork/getIdData",
				//				type : "POST",
				cache : false,
				contentType : "application/json; charset=UTF-8",
				success : function(data) {
					var obj = eval(data);
					$("input#form_id").autocomplete(
							 obj
							,
						{
							minChars : 0,
							matchContains : true,
							autoFill : false,
							mustMatch : false,
							width : 310,
							formatItem : function(row, i, max) {
								return "#" + row.to + " : " + row.name + "["
										+ row.id + "]";
							},
							formatMatch : function(row, i, max) {
								return row.name + " " + row.to;
							},
							formatResult : function(row) {
								return row.id;
							}
					});
				}
			});
			
			 $.ajax({
					url : "project/createWork/getWorkData",
					//				type : "POST",
					cache : false,
					contentType : "application/json; charset=UTF-8",
					success : function(data) {
						var obj = eval(data);
						$("input#form_upperWork").autocomplete(
								obj,
								{
									minChars : 0,
									matchContains : true,
									autoFill : false,
									mustMatch : false,
									width : 310,
									formatItem : function(row, i, max) {
										return "#" + row.to + " : " + row.title
												+ "[" + row.state + "]";
									},
									formatMatch : function(row, i, max) {
										return row.title + " " + row.to;
									},
									formatResult : function(row) {
										return row.to;
									}
								});
					}
				});
			 $.ajax({
					url : "project/createWork/getDocData",
					//				type : "POST",
					cache : false,
					contentType : "application/json; charset=UTF-8",
					success : function(data) {
						var obj = eval(data);
						$("input#form_document").autocomplete(
								obj,
								{
									minChars : 0,
									matchContains : true,
									autoFill : false,
									mustMatch : false,
									width : 310,
									formatItem : function(row, i, max) {
										return "#" + row.to + " : " + row.title
												+ "[" + row.writer + "]";
									},
									formatMatch : function(row, i, max) {
										return row.title + " " + row.to;
									},
									formatResult : function(row) {
										return row.to;
									}
								});
					}
				});
				$.ajax({
					url : "project/createWork/getFileData",
					//				type : "POST",
					cache : false,
					contentType : "application/json; charset=UTF-8",
					success : function(data) {
						var obj = eval(data);
						$("input#form_file").autocomplete(
								obj,
								{
									minChars : 0,
									matchContains : true,
									autoFill : false,
									mustMatch : false,
									width : 310,
									formatItem : function(row, i, max) {
										return "#" + row.to + " : " + row.title
												+ "[" + row.size + "]";
									},
									formatMatch : function(row, i, max) {
										return row.title + " " + row.to;
									},
									formatResult : function(row) {
										return row.to;
									}
								});
					}
			});
			
			$(document).ready(function(){
				$('input#form_workTitle').val('${work.workTitle}');
				var workExplanation = '${work.workExplanation}';
				workExplanation = workExplanation.replace(/<br>/g,"\n");
				$('textarea#workExplanation').val(workExplanation);
				$('input#form_id').val('${work.id}');
				$("select#form_workType option[value='${work.workType}']").attr("selected", true);
				$("select#form_workState option[value='${work.workState}']").attr("selected", true);
				$("select#form_workPriority option[value='${work.workPriority}']").attr("selected", true);
				$('input#form_coWorkers').val('${work.coWorkers}');
				$("select#form_workProgress option[value='${work.workProgress}']").attr("selected",true);
				$("input#form_startDate").val("${startDateFormat}"); //수정해야댄다
				$("input#form_deadDate").val("${deadDateFormat}"); //수정해야댄다
				$("input#form_upperWork").val("${workTracer.upperWorkNo}"); //수정해야댄다
				$("input#form_document").val("${workDocFileTracer.docNo}"); //수정해야댄다
				$("input#form_file").val("${workDocFileTracer.fileNo}"); //수정해야댄다
			});
			
			$.ajax({
				url : "project/createWork/getIdData",
				//				type : "POST",
				cache : false,
				contentType : "application/json; charset=UTF-8",
				success : function(data) {
					var obj = eval(data);
					for( var val in obj){
						
						$('select#form_coWorkers2').append("<option value="+obj[val].id+">"+obj[val].name+"</option>");
					}
				}
			});
			
			$('input#addMember').click(function(){
				if($('input#form_coWorkers').val() != ""){
					var data = $('input#form_coWorkers').val();
					var append = $('select#form_coWorkers2 option:selected').val();
					
					if(data.indexOf(append) == -1){ //해당 문자열 있다면 안들어감
						data = data + ", ";
						data = data + append;
						$('input#form_coWorkers').val(data);
					}
				}else{
					var data = $('select#form_coWorkers2 option:selected').val();
					$('input#form_coWorkers').val(data);
				}
			});
		</script>
	</div>
</div>
